package com.study.meng.bigevent.service.impl;

import com.study.meng.bigevent.common.utils.ThreadLocalUtil;
import com.study.meng.bigevent.entity.Category;
import com.study.meng.bigevent.entity.User;
import com.study.meng.bigevent.mapper.UserMapper;
import com.study.meng.bigevent.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    //根据用户名查询用户信息
    @Override
    public User findByUserName(String username) {
        return userMapper.selectByUserName(username);
    }

    @Override
    public boolean update(User user) {
        // 更新用户信息
        return userMapper.updateById(user) > 0;
    }

    @Override
    public boolean updateAvatar(String avatar) {
        Integer userId = ThreadLocalUtil.getCurrentUser();
        return userMapper.updateAvatar(avatar,userId) > 0;
    }

    @Override
    public boolean udpatePwd(User user) {
        return userMapper.updatePwd(user) > 0;
    }

    @Override
    public User findByUserId(Integer userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public boolean delete(Integer userId) {
        return userMapper.deleteById(userId) > 0;
    }


    //注册用户信息
    @Override
    public boolean register(User user) {
        return userMapper.insert(user) > 0;
    }

}
